<html xmlns:th="http://www.thymeleaf.org">
<div th:fragment="navbar" id="navbar" class="navbar navbar-fixed-top navbar-default ace-save-state">
    <div class="navbar-container ace-save-state" id="navbar-container">
        <button type="button" class="navbar-toggle menu-toggler pull-left fixed" id="menu-toggler"
                data-target="#sidebar">
            <span class="sr-only">Toggle sidebar</span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>

            <span class="icon-bar"></span>
        </button>
        <div class="navbar-header pull-left">
            <a href="#" class="navbar-brand">
                <small>
                    <i class="fa fa-desktop"></i>
                    幸福向北后台管理系统
                </small>
            </a>
        </div>

        <div class="navbar-buttons navbar-header pull-right" role="navigation">
            <ul class="nav ace-nav">
                <li class="light-blue dropdown-modal">
                    <a data-toggle="dropdown" href="#" class="dropdown-toggle">
                        <img class="nav-user-photo" th:src="@{/ace/images/avatars/avatar2.png}" alt="Jason's Photo"/>
                        <span class="user-info">
									<big th:text="${session.sysUser.account}"></big>
									<small th:text="${session.sysUser.nickname}">Administrator</small>
								</span>

                        <i class="ace-icon fa fa-caret-down"></i>
                    </a>

                    <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                        <li>
                            <a href="#update-password-modal" data-toggle="modal">
                                <i class="ace-icon fa fa-key"></i>
                                修改密码
                            </a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="#" th:href="@{/logout}">
                                <i class="ace-icon fa fa-power-off"></i>
                                退出登录
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div><!-- /.navbar-container -->

    <script>
        var valid_pwd_form;
        $(function () {
            valid_pwd_form = $("#pwd-form").validate({
                errorElement: 'div',
                errorClass: 'help-block',
                focusInvalid: false,
                ignore: "",
                rules: {
                    oldPwd: {
                        required: true,
                        rangelength: [6, 18],
                        remote: {
                            url: "management/checkPassword",
                            type: "post",
                            data: {
                                oldPwd: function () {
                                    return $("#oldPwd").val();
                                }
                            }
                        }
                    },
                    newPwd: {
                        required: true,
                        rangelength: [6, 18],
                        equalTo: "#confirmPwd"
                    },
                    confirmPwd: {
                        required: true,
                        rangelength: [6, 18],
                        equalTo: "#newPwd"
                    }
                },
                messages: {
                    oldPwd: {
                        required: "密码不能为空",
                        rangelength: "密码长度必须在6到18个字符之间",
                        remote: "原密码错误，请重新输入"
                    },
                    newPwd: {
                        required: "密码不能为空",
                        rangelength: "密码长度必须在6到18个字符之间",
                        equalTo: "两次密码输入不一致"
                    },
                    confirmPwd: {
                        required: "密码不能为空",
                        rangelength: "密码长度必须在6到18个字符之间",
                        equalTo: "两次密码输入不一致"
                    }
                }, highlight: function (e) {
                    $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
                }, success: function (e) {
                    $(e).closest('.form-group').removeClass('has-error');
                    $(e).remove();
                }, errorPlacement: function (error, element) {
                    if (element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                        var controls = element.closest('div[class*="col-"]');
                        if (controls.find(':checkbox,:radio').length > 1) controls.append(error);
                        else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                    } else if (element.is('.select2')) {
                        error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                    }
                    else if (element.is('.chosen-select')) {
                        error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                    }
                    else {
                        error.insertAfter(element.parent());
                    }
                }
            });

            //模态框隐藏事件
            $("#update-password-modal").on("hide.bs.modal", function () {
                $("#pwd-form")[0].reset();
                valid_pwd_form.resetForm();
                $("#pwd-form .form-group").removeClass("has-error");
            });

            $("#savePwd").click(function () {
                if ($("#pwd-form").valid()) {
                    $.post("management/updatePassword", {password: $("#newPwd").val()}, function () {
                        $("#update-password-modal").modal("hide");
                        bootbox.alert("密码修改成功，请重新登录!", function () {
                            window.location.href = "../logout";
                        });
                    });
                }
            });
        });

        $.ajaxSetup({
            dataFilter: function (response) {
                if (response.indexOf('<title>智慧党建管理系统</title>') !== -1) {
                    window.location.href = '${base}?ot';
                    return "";
                } else {
                    return response;
                }
            }
        });
    </script>
</div>
</html>